﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using ARR.Entities.Gateways;

namespace ARR.Entities
{
    [DataContract]
    [Serializable]
    public class SalesCategoryComparison : EntityBase
    {
        [DataMember]
        SalesCategoryComparisonRow row;

        public SalesCategoryComparison(SalesCategoryComparisonRow row)
        {
            this.row = row;
        }

        public SalesCategoryComparison()
        {
            row = new SalesCategoryComparisonRow();
        }

        public override void Initialize()
        {
            row = new SalesCategoryComparisonRow();
        }

        [DataMember]
        public string Name
        {
            get { return row.Name; }
            set { row.Name = value; }
        }

        [DataMember]
        public string Title
        {
            get { return row.Title; }
            set { row.Title = value; }
        }

        [DataMember]
        public short CategoryId
        {
            get { return row.CategoryId; }
            set { row.CategoryId = value; }
        }

        [DataMember]
        public string Category 
        { 
            get { return row.Category; }
            set { row.Category = value; }
        }

        [DataMember]
        public decimal Units 
        {
            get { return row.Units; }
            set { row.Units = value; }
        }

        [DataMember]
        public decimal Sales
        {
            get { return row.Sales; }
            set { row.Sales = value; }
        }

        [DataMember]
        public decimal GM
        {
            get { return row.GM; }
            set { row.GM = value; }
        }
        
        [DataMember]
        public decimal UnitsShare
        {
            get { return row.UnitsShare; }
            set { row.UnitsShare = value; }
        }

        [DataMember]
        public decimal SalesShare
        {
            get { return row.SalesShare; }
            set { row.SalesShare = value; }
        }

        [DataMember]
        public decimal GMShare
        {
            get { return row.GMShare; }
            set { row.GMShare = value; }
        }

        [DataMember]
        public decimal PIDiff
        {
            get { return row.PIDiff; }
            set { row.PIDiff = value; }
        }

        [DataMember]
        public decimal ChargeOffs
        {
            get { return row.ChargeOffs; }
            set { row.ChargeOffs = value; }
        }

        [DataMember]
        public decimal InventoryCost
        {
            get { return row.InventoryCost; }
            set { row.InventoryCost = value; }
        }

        [DataMember]
        public decimal LinearSpace
        {
            get { return row.LinearSpace; }
            set { row.LinearSpace = value; }
        }
        
        [DataMember]
        public int SKUs
        {
            get { return row.SKUs; }
            set { row.SKUs = value; }
        }

        [DataMember]
        public int Sales80
        {
            get { return row.Sales80; }
            set { row.Sales80 = value; }
        }
        
        [DataMember]
        public bool IsPriorYear
        {
            get { return row.IsPriorYear; }
            set { row.IsPriorYear = value; }
        }


        public decimal GMPercent
        {
            get
            {
                return Sales != 0 ? GM / Sales : 0;
            }
        }

        public decimal InvDays
        {
            get
            {
                return (Sales - GM) != 0 ? InventoryCost / ((Sales - GM) / 30) : 0;
            }
        }
        
        public decimal AnnualStockTurn
        {
            get
            {
                return InvDays != 0 ? 365 / InvDays : 0;
            }
        }

        public decimal GMROI
        {
            get
            {
                return InventoryCost != 0 ? GM / InventoryCost : 0;
            }
        }        

        public decimal SalesOverLinearMt
        {
            get
            {
                return LinearSpace != 0 ? Sales / LinearSpace : 0;
            }
        }

        public decimal GMROS
        {
            get
            {
                return LinearSpace != 0 ? GM / LinearSpace : 0;
            }
        }
        
        public decimal ActualMargin
        {
            get
            {
                return GMPercent + PIDiff + ChargeOffs;
            }
        }
        
    }
}
